package leetcode.每日一题;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author ：zsy
 * @date ：Created 2022/12/30 8:43 PM
 * @description：
 */
public class 至少在两个数组中出现的值 {
    @Test
    public void test() {
        System.out.println(new Solution().twoOutOfThree(new int[]{3, 1}, new int[]{2, 3}, new int[]{1, 2}));
    }

    class Solution {
        public List<Integer> twoOutOfThree(int[] nums1, int[] nums2, int[] nums3) {
            List<Integer> list = new ArrayList<>();
            int sum = 0;
            for (int num : nums1) {
                if ((sum ^ num) != 0) {
                    sum ^= num;
                }
            }
            for (int num : nums2) {
                if ((sum ^ num) == 0) {
                    list.add(num);
                } else {
                    sum ^= num;
                }
            }
            for (int num : nums3) {
                if ((sum ^ num) == 0) {
                    list.add(num);
                } else {
                    sum ^= num;
                }
            }
            return list;
        }
    }
}
